//
//  RootViewController.m
//  Golf
//
//  Created by mrbradle on 11/28/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "RootViewController.h"

#import "PGolfViewController.h"
#import "CGolfViewController.h"

@implementation RootViewController

@synthesize numRounds, numPlayers, numPlayersLabel, numRoundsSelector, numPlayersSlider;

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //[self.numPlayersSlider setNumberOfTickMarks:8];
    //[self.numPlayersSlider setAllowsTickMarksOnly:YES];
    [self.numPlayersSlider setMaximumValue:10];
    [self.numPlayersSlider setMinimumValue:2];
    [self.numPlayersSlider setValue:4.0];
    self.numPlayers = 4;
    self.numRounds = 3;
    [self.numPlayersLabel setText:[NSString stringWithFormat:@"%d",self.numPlayers]];

}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[super viewDidDisappear:animated];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return NO;
}

- (IBAction)changedRounds:(UISegmentedControl*)sender {
    switch (sender.selectedSegmentIndex) {
        case 0: self.numRounds = 3;
            break;
        case 1: self.numRounds = 6;
            break;
        case 2: self.numRounds = 9;
            break;
        default: self.numRounds = 18;
            
    }
    //self.numRounds = (sender).selectedSegmentIndex + 1;
    //self.numRounds = 4;
}

- (IBAction)changedPlayers:(UISlider*)sender {
    self.numPlayers = roundf(sender.value);
    [self.numPlayersLabel setText:[NSString stringWithFormat:@"%d",self.numPlayers]];
    //self.numPlayers = self.numPlayersLabel.
    
}

- (IBAction)startGame {
    
    NSMutableArray* temp = [NSMutableArray arrayWithCapacity:10];
    //[temp addObject:@"BIG MIKE"];
    for (int i = 0; i < 10; i++)
        [temp addObject:[NSString stringWithFormat:@"Player %d",i+1]];
    
    GolfGame* game = [[GolfGame alloc] initWithRounds:self.numRounds players:self.numPlayers names:temp];
    [game retain];
    CGolfViewController* golfVC = [[CGolfViewController alloc] initWithNibName:@"CGolfViewController" bundle:nil];
    [golfVC initGame:game];
    
    [self.navigationController pushViewController:golfVC animated:YES];
    
}

/*
 // Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	// Return YES for supported orientations.
	return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
 */

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 0;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell.
    return cell;
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        // Delete the row from the data source.
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
    else if (editingStyle == UITableViewCellEditingStyleInsert)
    {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    /*
    <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
    // ...
    // Pass the selected object to the new view controller.
    [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release];
	*/
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload
{
    [super viewDidUnload];

    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
}

- (void)dealloc
{
    [super dealloc];
}

@end
